package com.print;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.JApplet;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.codehaus.jackson.map.ObjectMapper;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import com.model.mt.BoxInfo;
import com.model.mt.DeliveryNotePrint;
import com.model.mt.PrintPrdInfo;
import com.sun.xml.internal.fastinfoset.stax.events.Util;
import com.swetake.util.Qrcode;
import com.util.JackUtil;

/**
 * 客户端标签打印
 * 
 * @author
 * 
 */
public class LabelApplet extends JApplet {

	private static final long serialVersionUID = -6391368515081034834L;

	public void print1(final String info) throws Exception {
		AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
			@Override
			public Object run() throws Exception {
				Label label = new Label();
				label.addDMCode(new DMCode(2, 2, 2, info));
				label.print();
				label.dispose();
				return null;
			}
		});
	}

	public void printSharp(final String sharpPartNo, final String sn, final String csn, final String r, final String hw,
			final String fw, final String sd) throws Exception {
		AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
			@Override
			public Object run() throws Exception {
				Label label = new Label();
				label.addText(new Text(2, 6, "Sharp Type", 1, 21, "S"));
				label.addText(new Text(22, 5.2, "Arial Unicode MS", 1, 14.5, sharpPartNo));
				label.addCode(new Code(3, 8.2, 4.3, 0.2, sn));
				label.addText(new Text(3, 15.1, "Arial Unicode MS", 0, 11, sn));
				label.addCode(new Code(3, 16.5, 4.3, 0.18, csn));
				label.addText(new Text(3, 23.5, "Arial Unicode MS", 0, 11, csn));
				label.addText(new Text(56.3, 6.4, "Arial Narrow", 0, 17, "RoHS"));
				label.addText(new Text(56.3, 9.8, "Arial Unicode MS", 0, 11, r));
				label.addText(new Text(56.3, 13.8, "Arial Unicode MS", 0, 11, hw));
				label.addText(new Text(56.3, 17.8, "Arial Unicode MS", 0, 11, fw));
				label.addText(new Text(2, 26.2, "Arial Unicode MS", 0, 11, sd));
				label.addText(new Text(47.5, 26.2, "Arial Unicode MS", 0, 11, "MADE IN CHINA"));
				label.print();
				label.dispose();
				return null;
			}
		});
	}

	public void print(final String boxID, final String modelName, final String pnlCnt, final String shtCnt,
			final String totalCnt, final String date, final String productSpec, String jsonAry) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 98, 0.2));
		label.addText(new Text(8.8, 7.1, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(51.2, 7.1, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(8.8, 12.1, "Arial", 0, 13, "Date:    " + date));
		label.addText(new Text(51.2, 12.1, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(63, 23.8, "Arial", 0, 13, "" + pnlCnt));
		label.addText(new Text(71.6, 23.8, "Arial ", 0, 13, "YIELD: 100%"));
		Text text = new Text(8.8, 17.8, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(8.8, 19, 7, 0.2, boxID);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(51.2, 17.8, "Arial", 0, 13, "Spec :" + productSpec));
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 8.8;
			double x2 = 51.2;
			double y = 29.3;
			double step = 3.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 2 == 0) {
					x = x1;
				} else {
					x = x2;
				}
				double _y = y + (i / 2) * step;
				label.addText(new Text(x, _y, "Arial", 0, 11, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintTM(final String boxID, final String customer_name, final String modelName, final String pnlCnt,
			final String shtCnt, final String totalCnt, final String date, final String productSpec,
			final String user_id, final String thickness, final String lotNo, String jsonAry, final String productCate,
			final String mtrllot) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(35.8, 6.1, "宋体", 0, 16, "出货标签"));
		label.addText(new Text(65.8, 6.1, "宋体", 0, 14, "供应商编码: CX"));
		Text text = new Text(3.8, 11.8, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(3.8, 13, 8, 0.25, boxID);
		try {
			label.addCode128(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(3.8, 24.1, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(3.8, 28.6, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(56.2, 28.6, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(3.8, 33.1, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(56.2, 33.1, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(3.8, 37.6, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(56.2, 37.6, "Arial", 0, 13, "Lot No  :" + lotNo));
		label.addText(new Text(3.8, 42.1, "Arial", 0, 13, "Pack  By:  " + user_id));
		label.addText(new Text(56.2, 42.1, "Arial", 0, 13, "Thickness  :" + thickness));
		label.addText(new Text(3.8, 46.6, "Arial", 0, 13, "Material Lot:  " + mtrllot));
		label.addText(new Text(3.8, 51.1, "Arial", 0, 13, "Order No:  "));
		label.addText(new Text(56.2, 46.6, "宋体", 0, 13, "Product Cate:" + productCate));

		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 3.8;
			double x2 = 35.8;
			double x3 = 68.8;
			double y = 60.3;
			double step = 3.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	// public void PrintTM(final String boxID, final String customer_name,final
	// String modelName,final String pnlCnt,final String shtCnt,final String
	// totalCnt,final String date,
	// final String productSpec,final String user_id, final String thickness,
	// final String lotNo, String jsonAry,final String productCate) {
	// ObjectMapper mapper = new ObjectMapper();
	// String[] ja = null;
	// try {
	// ja = mapper.readValue(jsonAry, String[].class);
	// } catch (Exception e) {
	// System.out.println("Error took place");
	// e.printStackTrace();
	// }
	// Label label = new Label(100, 100, 300);
	// label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
	// label.addText(new Text(8.8, 6.1, "宋体", 0, 18, "长信科技"));
	// label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "ROHS"));
	// label.addText(new Text(8.8, 11.1, "宋体", 0, 13, "Client Name: "
	// + customer_name));
	// label.addText(new Text(8.8, 15.6, "Arial", 0, 13, "Model: "
	// + modelName));
	// label.addText(new Text(56.2, 15.6, "Arial", 0, 13, "Q'TY(Q) :"
	// + shtCnt));
	// label.addText(new Text(8.8, 20.1, "Arial", 0, 13, "Date: "
	// + date));
	// label.addText(new Text(56.2, 20.1, "Arial", 0, 13, "Q'TY(S) :"
	// + totalCnt));
	// label.addText(new Text(8.8, 24.6, "Arial", 0, 13, "Size: "
	// + productSpec));
	// label.addText(new Text(56.2, 24.6, "Arial", 0, 13, "Lot No :"
	// + lotNo));
	// label.addText(new Text(8.8, 29.1, "Arial", 0, 13, "Pack By: "
	// + user_id));
	// label.addText(new Text(56.2, 29.1, "Arial", 0, 13, "Thickness :"
	// + thickness));
	// label.addText(new Text(8.8, 34.1, "Arial", 0, 13, "Order No: "));
	// label.addText(new Text(56.2, 34.1, "宋体", 0, 13, "Product Cate:"
	// + productCate));
	// Text text = new Text(8.8, 38.8, "Arial Black", 0, 15, boxID);
	// label.addText(text);
	// Code code = new Code(8.8, 40, 8, 0.25, boxID);
	//
	// try {
	// label.addCode128(code);
	// } catch (IOException e) {
	// e.printStackTrace();
	// }
	// if (ja == null) {
	//// System.out.println("Sheet array is empty");
	// } else {
	// double x1 = 8.8;
	// double x2 = 38.8;
	// double x3 = 68.8;
	// double y = 51.3;
	// double step = 3.5;
	// for (int i = 0; i < ja.length; i++) {
	// double x = 0;
	// if (i % 3 == 0) {
	// x = x1;
	// } else if ( i % 3 == 1){
	// x = x2;
	// }else{
	// x = x3;
	// }
	// double _y = y + (i/3)*step;
	// label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
	// }
	// }
	// try {
	// label.print();
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// label.dispose();
	// }
	public void PrintXPNEW(final String boxID, final String customer_name, final String typeup, final String typedown,
			final String pnlCnt, final String shtCnt, final String totalCnt, final String date,
			final String productSpec, final String lotNo, final String productCate) {

		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(8.8, 18, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 18, "Arial", 0, 13, "ROHS"));
		label.addText(new Text(8.8, 25, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(8.8, 35, "Arial", 0, 13, "TYPE:  "));
		label.addText(new Text(8.8, 32, "Arial", 0, 13, "            " + typeup));
		label.addText(new Text(56.2, 32, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addLine(new Line(20, 34.6, 30, 0.2, 0));
		label.addText(new Text(8.8, 39, "Arial", 0, 13, "            " + typedown));
		label.addText(new Text(8.8, 46, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(56.2, 39, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(8.8, 53, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(56.2, 46, "Arial", 0, 13, "Lot No  :" + lotNo));
		label.addText(new Text(8.8, 60, "Arial", 0, 13, "Order No:  "));
		label.addText(new Text(56.2, 53, "宋体", 0, 13, "Product Cate:" + productCate));
		Text text = new Text(8.8, 67, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(8.8, 69, 8, 0.25, boxID);

		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintBJ(final String boxID, final String customer_name, final String modelName, final String pnlCnt,
			final String shtCnt, final String totalCnt, final String material, final String date,
			final String productSpec, final String lotNo, final String jsonAry, final String productCate) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(8.8, 6.1, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "ROHS"));
		label.addText(new Text(8.8, 11.1, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(8.8, 15.6, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(56.2, 15.6, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(8.8, 20.1, "宋体", 0, 13, "Material:  " + material));
		label.addText(new Text(56.2, 20.1, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(8.8, 24.6, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(56.2, 24.6, "Arial", 0, 13, "Lot No  :" + lotNo));
		label.addText(new Text(8.8, 29.1, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(56.2, 29.1, "宋体", 0, 13, "Product Cate:" + productCate));
		label.addText(new Text(8.8, 33.6, "Arial", 0, 13, "Order No:  "));
		Text text = new Text(8.8, 37.6, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(8.8, 38.8, 9, 0.25, boxID);

		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 8.8;
			double x2 = 38.8;
			double x3 = 68.8;
			double y = 51.1;
			double step = 3.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintZH(final String boxID, final String customer_name, final String modelName, final String pnlCnt,
			final String shtCnt, final String totalCnt, final String date, final String productSpec, final String lotNo,
			final String jsonAry, final String productCate, final String invalidDate, final String mtrl_lot_id) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(35.8, 6.1, "宋体", 0, 16, "出货标签"));
		label.addText(new Text(65.8, 6.1, "宋体", 0, 14, "供应商编码: CX"));
		Text text = new Text(3.8, 11.8, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(3.8, 13, 9, 0.22, boxID);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(3.8, 26.1, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(3.8, 30.6, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(53.2, 30.6, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(3.8, 35.1, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(53.2, 35.1, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(3.8, 39.6, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(53.2, 39.6, "Arial", 0, 13, "Lot No:" + lotNo));
		label.addText(new Text(3.8, 44.1, "Arial", 0, 13, "Invalid Date:  " + invalidDate));
		label.addText(new Text(53.2, 44.1, "宋体", 0, 13, "Product Cate:" + productCate));
		label.addText(new Text(3.8, 48.6, "Arial", 0, 13, "Material Lot:  " + mtrl_lot_id));
		label.addText(new Text(3.8, 53.1, "Arial", 0, 13, "Order No:  "));

		// try {
		// label.addCode(code);
		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 3.8;
			double x2 = 35.8;
			double x3 = 68.8;
			double y = 65.8;
			double step = 3.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	// public void PrintZH(final String boxID,final String customer_name,final
	// String modelName,final String pnlCnt,final String shtCnt,final String
	// totalCnt,
	// final String date,final String productSpec,final String lotNo,final
	// String jsonAry,final String productCate,
	// final String invalidDate) {
	// ObjectMapper mapper = new ObjectMapper();
	// String[] ja = null;
	// try {
	// ja = mapper.readValue(jsonAry, String[].class);
	// } catch (Exception e) {
	// System.out.println("Error took place");
	// e.printStackTrace();
	// }
	// Label label = new Label(100, 100, 300);
	// label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
	// label.addText(new Text(8.8, 6.1, "宋体", 0, 18, "长信科技"));
	// label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "ROHS"));
	// label.addText(new Text(8.8, 11.1, "宋体", 0, 13, "Client Name: "
	// + customer_name));
	// label.addText(new Text(8.8, 15.6, "Arial", 0, 13, "Model: "
	// + modelName));
	// label.addText(new Text(56.2, 15.6, "Arial", 0, 13, "Q'TY(Q) :"
	// + shtCnt));
	// label.addText(new Text(8.8, 20.1, "Arial", 0, 13, "Date: "
	// + date));
	// label.addText(new Text(56.2, 20.1, "Arial", 0, 13, "Q'TY(S) :"
	// + totalCnt));
	// label.addText(new Text(8.8, 24.6, "Arial", 0, 13, "Size: "
	// + productSpec));
	// label.addText(new Text(56.2, 24.6, "Arial", 0, 13, "Lot No:"
	// + lotNo));
	// label.addText(new Text(8.8, 29.6, "Arial", 0, 13, "Invalid Date: "
	// + invalidDate));
	// label.addText(new Text(56.2, 29.6, "宋体", 0, 13, "Product Cate:"
	// + productCate));
	// label.addText(new Text(8.8, 34.6, "Arial", 0, 13, "Order No: "));
	// Text text = new Text(8.8, 39.3, "Arial Black", 0, 15, boxID);
	// label.addText(text);
	// Code code = new Code(8.8, 40.5, 9, 0.25, boxID);
	//
	// try {
	// label.addCode(code);
	// } catch (IOException e) {
	// e.printStackTrace();
	// }
	// if (ja == null) {
	// System.out.println("Sheet array is empty");
	// } else {
	// double x1 = 8.8;
	// double x2 = 38.8;
	// double x3 = 68.8;
	// double y = 63.8;
	// double step = 3.5;
	// for (int i = 0; i < ja.length; i++) {
	// double x = 0;
	// if (i % 3 == 0) {
	// x = x1;
	// } else if ( i % 3 == 1){
	// x = x2;
	// }else{
	// x = x3;
	// }
	// double _y = y + (i/3)*step;
	// label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
	// }
	// }
	// try {
	// label.print();
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// label.dispose();
	// }
	public void PrintJDF(final String boxID, final String customer_name, final String modelName, final String pnlCnt,
			final String shtCnt, final String totalCnt, final String date, final String productSpec, final String lotNo,
			final String jsonAry, final String productCate) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(8.8, 6.1, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "ROHS"));
		label.addText(new Text(8.8, 11.1, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(8.8, 15.6, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(56.2, 15.6, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(8.8, 20.1, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(56.2, 20.1, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(8.8, 24.6, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(56.2, 24.6, "Arial", 0, 13, "Lot No  :" + lotNo));
		label.addText(new Text(8.8, 29.6, "Arial", 0, 13, "Order No:  " + pnlCnt));
		label.addText(new Text(56.2, 29.6, "宋体", 0, 13, "Product Cate:" + productCate));
		Text text = new Text(8.8, 34.3, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(8.8, 35.5, 8, 0.25, boxID);

		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 8.8;
			double x2 = 37.8;
			double x3 = 68.8;
			double y = 46.8;
			double step = 3.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintXP(final String boxID, final String customer_name, final String modelName, final String pnlCnt,
			final String shtCnt, final String totalCnt, final String date, final String productSpec, final String lotNo,
			final String jsonAry, final String productCate) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(8.8, 6.1, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "ROHS"));
		label.addText(new Text(8.8, 11.1, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(8.8, 15.6, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(56.2, 15.6, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(8.8, 20.1, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(56.2, 20.1, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(8.8, 24.6, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(56.2, 24.6, "Arial", 0, 13, "Lot No  :" + lotNo));
		label.addText(new Text(8.8, 29.6, "Arial", 0, 13, "Order No:  "));
		label.addText(new Text(56.2, 29.6, "宋体", 0, 13, "Product Cate:" + productCate));
		Text text = new Text(8.8, 34.3, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(8.8, 35.5, 8, 0.25, boxID);

		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 5.8;
			double x2 = 37.2;
			double x3 = 68.6;
			double y = 46.8;
			double step = 3.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 11, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintPlt(final String pallet_id, final String customer_name, final String model_name, final String date,
			final String pnl_qty, final String totalCnt) {

		ObjectMapper mapper = new ObjectMapper();
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 98, 0.2));
		label.addText(new Text(8.8, 6.1, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "ROHS"));
		label.addText(new Text(8.8, 13.1, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(8.8, 20.6, "Arial", 0, 13, "Model:  " + model_name));
		label.addText(new Text(8.8, 27.6, "Arial", 0, 13, "QTY:  " + pnl_qty));
		label.addText(new Text(8.8, 34.6, "Arial", 0, 13, "Total QTY:  " + totalCnt));
		label.addText(new Text(8.8, 41.6, "Arial", 0, 13, "PACK DATE:  " + date));
		label.addText(new Text(8.8, 48.6, "Arial", 0, 13, "PALLET:  " + pallet_id));
		Code code = new Code(8.8, 50.6, 9, 0.25, pallet_id);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintJDF4jb(final String boxID, final String modelName, final String pnlCnt, final String shtCnt,
			final String totalCnt, final String date, final String jsonAry, final String customerName,
			final String lotNo, final String productSpec, final String productCate, final String woId) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 99, 98, 0.2));
		label.addText(new Text(2.8, 5.3, "宋体", 0, 13, "Client Name: " + customerName));
		label.addText(new Text(2.8, 9.8, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(56.2, 9.8, "Arial", 0, 13, "QTY:  " + shtCnt));
		label.addText(new Text(2.8, 14.3, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(56.2, 14.3, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(2.8, 18.8, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(56.2, 18.8, "Arial", 0, 13, "Lot No:" + lotNo));
		label.addText(new Text(2.8, 23.3, "Arial", 0, 13, "Wo Id:  " + woId));
		label.addText(new Text(56.2, 23.3, "宋体", 0, 13, "Product Cate:" + productCate));

		// label.addText(new Text(56.2, 19.5, "Arial", 0, 13, "" + pnlCnt));
		// label.addText(new Text(66, 19.5, "Arial ", 0, 13, "YIELD: 100%"));
		Text text = new Text(5.2, 29.2, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(5.2, 31, 9, 0.20, boxID);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (!boxID.substring(0, 2).equals("GX")) {
			label.addText(new Text(8.8, 94.8, "Arial", 0, 11, "MADE IN CHINA"));
			label.addText(new Text(8.8, 97.5, "Arial", 0, 11, "BOE HF OPTOELECTRONICS TECHNOLOGY CO.,LTD"));
		}
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 9.8;
			double x2 = 52.2;
			double y = 43;
			double step = 2.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 2 == 0) {
					x = x1;
				} else {
					x = x2;
				}
				double _y = y + (i / 2) * step;
				label.addText(new Text(x, _y, "Arial", 0, 11, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintJX(final String customer_id, final String mode_id, final String date, final String prd_spec,
			final String wo_id, final String woCnt, final String prdCnt, final String boxCnt, final String totalCnt,
			final String jsonAry) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(55, 60, 300);
		label.addRectangle(new Rectangle(1, 1, 53, 68, 0.2));
		label.addText(new Text(5.8, 13.5, "宋体", 0, 8, "客户代码"));
		label.addText(new Text(23.8, 13.5, "Arial", 0, 8, "006"));
		label.addLine(new Line(1, 18, 60, 0.2, 0));
		label.addText(new Text(5.8, 18.5, "宋体", 0, 8, "客户型号"));
		label.addText(new Text(23.8, 18.5, "Arial", 0, 8, "C2598B50(36)"));
		label.addText(new Text(5.8, 23.5, "宋体", 0, 8, "来料日期"));
		label.addText(new Text(23.8, 23.5, "Arial", 0, 8, "2014-05-13"));
		label.addText(new Text(5.8, 28.5, "宋体", 0, 8, "规格"));
		label.addText(new Text(23.8, 28.5, "Arial", 0, 8, "750*580*1.0"));
		label.addText(new Text(5.8, 33.5, "宋体", 0, 8, "生产订单号"));
		label.addText(new Text(23.8, 33.5, "Arial", 0, 8, "JD703827"));
		label.addText(new Text(5.8, 38.5, "宋体", 0, 8, "订单数量"));
		label.addText(new Text(23.8, 38.5, "Arial", 0, 8, "180"));
		label.addText(new Text(5.8, 43.5, "宋体", 0, 8, "本箱数量"));
		label.addText(new Text(23.8, 43.5, "Arial", 0, 8, "30"));
		label.addText(new Text(5.8, 48.5, "宋体", 0, 8, "箱号"));
		label.addText(new Text(23.8, 48.5, "Arial", 0, 8, "1" + "/" + "10"));
		label.addText(new Text(5.8, 53.5, "Arial", 0, 8, "BOXID"));
		Code code = new Code(23.8, 53.5, 8, 0.25, "D0506022");
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintHSD(final String box_id, final String mode_id, final String mtrl_id, final String shtCnt,
			final String totalCnt, final String strDate, final String remark, final String Rev, final String jsonAry) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(97, 98, 300);
		label.addText(new Text(5.8, 8.5, "Arial", 0, 16, mode_id));
		label.addText(new Text(70.8, 8.5, "Arial", 0, 14, strDate));
		label.addText(new Text(5.8, 14.5, "Arial", 0, 14, "Label ID:" + box_id));
		Code code = new Code(8.8, 16.5, 8, 0.20, box_id);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(65.8, 15.5, "Arial", 0, 14, "QTY:" + shtCnt + "/" + totalCnt));
		label.addText(new Text(65.8, 20.5, "Arial", 0, 14, "Rev." + Rev));
		label.addText(new Text(5.8, 28.5, "Arial", 0, 14, "P/N:" + mtrl_id));
		label.addText(new Text(65.8, 28.5, "Arial", 0, 14, "REMARK:" + remark));
		Code code2 = new Code(8.8, 30.5, 8, 0.25, mtrl_id);
		try {
			label.addCode(code2);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 9.8;
			double x2 = 52.2;
			double y = 43;
			double step = 2.8;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 2 == 0) {
					x = x1;
				} else {
					x = x2;
				}
				double _y = y + (i / 2) * step;
				label.addText(new Text(x, _y, "Arial", 0, 11, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintTWQC(final String customer_name, final String mdlcate, final String strDate, final String mdl_typ,
			final String model_name, final String shtCnt, final String box_id, final String soid,
			final String cus_cus_id, final String grade, final String remark) {

		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 10, 96, 78, 0.2));
		label.addLine(new Line(1, 20, 96, 0.2, 0));
		label.addLine(new Line(1, 30, 96, 0.2, 0));
		label.addLine(new Line(1, 40, 96, 0.2, 0));
		label.addLine(new Line(1, 60, 96, 0.2, 0));
		label.addLine(new Line(1, 70, 96, 0.2, 0));

		label.addLine(new Line(12, 10, 78, 0.2, -90));
		label.addLine(new Line(58, 10, 60, 0.2, -90));
		label.addLine(new Line(65, 10, 60, 0.2, -90));

		label.addText(new Text(2.5, 16, "宋体", 0, 10, "供应商"));
		label.addText(new Text(13, 16.5, "宋体", 0, 15, customer_name));
		label.addText(new Text(1.5, 26, "宋体", 0, 10, "生产时间"));
		label.addText(new Text(13, 26.5, "宋体", 0, 15, strDate));
		label.addText(new Text(1.5, 36, "宋体", 0, 10, "产品型号"));
		label.addText(new Text(13, 36.5, "宋体", 0, 15, mdl_typ));
		label.addText(new Text(1.5, 51, "宋体", 0, 10, "出货料号"));
		Code code1 = new Code(13.5, 41.5, 18, 0.25, model_name);
		try {
			label.addCodes(code1);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(3, 64, "宋体", 0, 10, "Model"));
		label.addText(new Text(3.5, 67.5, "宋体", 0, 10, "name"));
		label.addText(new Text(13, 66.5, "宋体", 0, 15, cus_cus_id));
		label.addText(new Text(2.5, 79, "宋体", 0, 10, "Remark"));
		label.addText(new Text(13, 79.5, "宋体", 0, 15, remark));

		label.addText(new Text(59, 16, "宋体", 0, 10, "工艺"));
		label.addText(new Text(66, 16.5, "宋体", 0, 15, mdlcate));
		label.addText(new Text(59, 26, "宋体", 0, 10, "数量"));
		label.addText(new Text(66, 26.5, "宋体", 0, 15, shtCnt));
		label.addText(new Text(60, 36, "宋体", 0, 10, "PO"));
		label.addText(new Text(66, 36.5, "宋体", 0, 15, soid));
		label.addText(new Text(59, 51, "宋体", 0, 10, "箱号"));
		Code code = new Code(66.5, 41.5, 18, 0.25, box_id);
		try {
			label.addCodes(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(58.5, 66, "宋体", 0, 10, "Grade"));
		label.addText(new Text(66, 66.5, "宋体", 0, 15, grade));
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintMT3(final String printer, final String B1, final String customer_name, final String maker,
			final String model, final String shtCnt, final String wocate, final String strDate, final String cellcnt,
			final String model_name, final String productSpec, final String lotNo, final String soid,
			final String box_id, final String prdCate, final String th, final String route, final String jsonAry,
			final String toad) {
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {
				System.out.println("pringMT3 ....");
				ObjectMapper mapper = new ObjectMapper();
				String[] ja = null;
				try {
					ja = mapper.readValue(jsonAry, String[].class);
				} catch (Exception e) {
					System.out.println("Error took place");
					e.printStackTrace();
				}

				String sht1 = "";
				String sht2 = "";
				String sht3 = "";
				String sht4 = "";
				String sht5 = "";
				String sht6 = "";
				String sht7 = "";
				String sht8 = "";
				String sht9 = "";
				String sht10 = "";
				String sht11 = "";
				String sht12 = "";
				String sht13 = "";
				String sht14 = "";
				String sht15 = "";
				String sht16 = "";
				String sht17 = "";
				String sht18 = "";
				String sht19 = "";
				String sht20 = "";
				System.out.println("p1:" + ja.length);

				sht1 = ja[0];
				sht2 = ja[1];
				sht3 = ja[2];
				sht4 = ja[3];
				sht5 = ja[4];
				sht6 = ja[5];
				sht7 = ja[6];
				sht8 = ja[7];
				sht9 = ja[8];
				sht10 = ja[9];
				sht11 = ja[10];
				sht12 = ja[11];
				sht13 = ja[12];
				sht14 = ja[13];
				sht15 = ja[14];
				sht16 = ja[15];
				sht17 = ja[16];
				sht18 = ja[17];
				sht19 = ja[18];
				sht20 = ja[19];
				System.out.println("p2:" + ja[0] + "\\" + ja[1] + "\\" + ja[2] + "\\" + ja[3] + "\\" + ja[4]);
				System.out.println(
						"p3:" + "(" + sht1 + "\\" + sht2 + "\\" + sht3 + sht4 + sht5 + sht6 + sht7 + sht8 + sht9 + sht10
								+ sht11 + sht12 + sht13 + sht14 + sht15 + sht16 + sht17 + sht18 + sht19 + sht20 + ")");
				System.out.println("p4:" + B1 + customer_name + maker + model + shtCnt + wocate + strDate + cellcnt
						+ model_name + productSpec + lotNo + soid + box_id + prdCate + th + route);
				try {
					ActiveXComponent axc = new ActiveXComponent("pt1.ct33");
					System.out.println("1007");
					Dispatch dispatch = axc.getObject();
					System.out.println("1009");
					Variant v = Dispatch.call(dispatch, "ct33", printer, B1, customer_name, maker, model, shtCnt,
							wocate, strDate, cellcnt, model_name, productSpec, lotNo, soid, box_id, prdCate, th, route,
							sht1, sht2, sht3, sht4, sht5, sht6, sht7, sht8, sht9, sht10, sht11, sht12, sht13, sht14,
							sht15, sht16, sht17, sht18, sht19, sht20, toad);
					System.out.println("1013");
				} catch (Exception e) {
					System.out.println("Error dll");
					e.printStackTrace();
				}
				return null;
			}
		});
	}

	public void PrintTEST(final String box_id) {

		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 96, 46, 0.2));

		label.addText(new Text(2.5, 5, "宋体", 0, 9, box_id));
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
		// AccessController.doPrivileged(new PrivilegedAction<Object>() {
		// @Override
		// public Object run() {
		// ActiveXComponent axc = new ActiveXComponent("pt1.ct7");
		// String B1="wfq";
		// String customer_name="wfq";
		// String maker="wfq";
		// String model="wfq";
		// String shtCnt="wfq";
		// String wocate="wfq";
		// String strDate="wfq";
		// String cellcnt="wfq";
		// String model_name="wfq";
		// String productSpec="wfq";
		// String lotNo="wfq";
		// String soid="wfq";
		//
		// String prdCate="wfq";
		// String th="wfq";
		// String route="wfq";
		// String sht1="ssdf";
		// String sht2="";
		// String sht3="";
		// String sht4="";
		// String sht5="";
		// String sht6="";
		// String sht7="";
		// String sht8="";
		// String sht9="";
		// String sht10="";
		// String sht11="";
		// String sht12="";
		// String sht13="";
		// String sht14="";
		// String sht15="";
		// String sht16="";
		// String sht17="";
		// String sht18="";
		// String sht19="";
		// String sht20="";
		//
		// Dispatch dispatch = axc.getObject();
		// Variant v = Dispatch.call(dispatch,
		// "ct7",B1,customer_name,maker,model,shtCnt,wocate,strDate,cellcnt,model_name,productSpec,lotNo,
		// soid,box_id,prdCate,th,route,sht1,sht2,sht3,sht4,sht5,sht6,sht7,sht8,sht9,sht10,sht11,sht12,sht13,sht14,sht15,
		// sht16,sht17,sht18,sht19,sht20);
		// return null;
		// }
		// });
	}

	public void PrintZHNEW(final String boxID, final String customer_name, final String modelName, final String tmmtrl,
			final String pnlCnt, final String shtCnt, final String totalCnt, final String date,
			final String productSpec, final String lotNo, final String jsonAry, final String productCate,
			final String invalidDate, final String mtrl_lot_id) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(35.8, 6.1, "宋体", 0, 16, "出货标签"));
		label.addText(new Text(65.8, 6.1, "宋体", 0, 14, "供应商编码: CX"));
		Text text = new Text(3.8, 11.8, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(3.8, 13, 9, 0.22, boxID);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(3.8, 26.1, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(3.8, 30.6, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(50, 30.6, "Arial", 0, 13, "Model2: " + tmmtrl));
		label.addText(new Text(50, 35.1, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(3.8, 35.1, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(50, 39.6, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(3.8, 39.6, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(50, 44.1, "Arial", 0, 13, "Lot No:" + lotNo));
		label.addText(new Text(3.8, 44.1, "Arial", 0, 13, "Invalid Date:  " + invalidDate));
		label.addText(new Text(50, 48.6, "宋体", 0, 13, "Product Cate:" + productCate));
		label.addText(new Text(3.8, 48.6, "Arial", 0, 13, "Material Lot:  " + mtrl_lot_id));
		label.addText(new Text(3.8, 53.1, "Arial", 0, 13, "Order No:  " + pnlCnt));

		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 3.8;
			double x2 = 35.8;
			double x3 = 68.8;
			double y = 65.8;
			double step = 3.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintForHc098(final String printer, final String gys, final String boxId, final String cusName,
			final String mode, final String date, final String size, final String indate, final String mtrllot,
			final String orderno, final String mode2, final String cnt, final String allcnt, final String lotno,
			final String procate, final String jsonAry) {
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {

				System.out.println("Start3");
				ObjectMapper mapper = new ObjectMapper();
				String[] ja = null;
				try {
					ja = mapper.readValue(jsonAry, String[].class);
				} catch (Exception e) {
					System.out.println("Error took place");
					e.printStackTrace();
				}
				String sht = "";
				for (int i = 0; i < 20; i++) {
					sht = sht + ja[i] + ",";
				}
				ActiveXComponent axc = new ActiveXComponent("pt1.ct28");

				Dispatch dispatch = axc.getObject();
				Variant v = Dispatch.call(dispatch, "ct28", printer, gys, boxId, cusName, mode, date, size, indate,
						mtrllot, orderno, mode2, cnt, allcnt, lotno, procate, sht);

				return null;
			}
		});
	}

	public void PrintES(final String printer, final String ps, final String mkr, final String wocate,
			final String mtrlId, final String qty, final String jgyq, final String date, final String outdate,
			final String boxId, final String thickness, final String dir, final String user, final String note) {
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {

				System.out.println("Start2");

				ActiveXComponent axc = new ActiveXComponent("pt1.ct31");

				Dispatch dispatch = axc.getObject();
				Variant v = Dispatch.call(dispatch, "ct31", printer, ps, mkr, wocate, mtrlId, qty, jgyq, date, outdate,
						boxId, thickness, dir, user, note);

				return null;
			}
		});
	}

	// 003客户标签
	public void PrintYZBDBox(final String cus_id, final String box_id, final String cpt_type, final String suffix,
			final String cpt_no, final String glass1, String glass2, final String item_no, final String cnt,
			final String date, final String okcnt, final String inspector, final String remark, final String substrate,
			final String tcn_no, final String pjlx) {

		LabelJX label = new LabelJX(100, 100, 300);
		label.addText(new Text(10, 5, "Arial", 0, 17, "CHUNGHWA PICTURE TUBES,LTD."));
		label.addRectangle(new Rectangle(3, 7, 95, 73, 0.3));
		label.addText(new Text(4, 11, "Arial", 0, 12, "Customer"));
		label.addLine(new Line(3, 12.5, 95, 0.3, 0));
		label.addText(new Text(4, 20, "Arial", 0, 12, "Package NO."));
		label.addLine(new Line(3, 26, 95, 0.3, 0));
		Code code = new Code(30, 13, 12, 0.30, box_id);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addLine(new Line(28, 7, 73, 0.3, -90));
		label.addText(new Text(4, 29.5, "Arial", 0, 12, "CPT Type"));
		label.addLine(new Line(3, 31.5, 95, 0.3, 0));
		label.addText(new Text(4, 37, "Arial", 0, 12, "CPT NO."));
		label.addLine(new Line(3, 40, 95, 0.3, 0));
		label.addText(new Text(4, 44, "Arial", 0, 11, "Customer Item NO."));
		label.addLine(new Line(3, 46.5, 95, 0.3, 0));
		label.addText(new Text(4, 50, "Arial", 0, 12, "Quantity"));
		label.addLine(new Line(3, 52, 95, 0.3, 0));
		label.addText(new Text(4, 55.5, "Arial", 0, 12, "OK/Total"));
		label.addText(new Text(4, 59.5, "Arial", 0, 12, "Count(pcs)"));
		label.addLine(new Line(3, 61.5, 95, 0.3, 0));
		label.addText(new Text(4, 65, "Arial", 0, 12, "Remark"));
		label.addLine(new Line(3, 67, 95, 0.3, 0));
		label.addText(new Text(4, 71, "Arial", 0, 12, "Substrate Type"));
		label.addLine(new Line(3, 73.5, 95, 0.3, 0));
		label.addText(new Text(4, 77, "Arial", 0, 12, "TCN NO."));
		label.addText(new Text(40, 10.5, "Arial", 0, 12, cus_id));
		label.addText(new Text(29, 29.5, "Arial", 0, 12, cpt_type));
		label.addText(new Text(65, 29.5, "Arial", 0, 12, "Suffix"));
		label.addLine(new Line(64, 26, 14, 0.3, -90));
		label.addText(new Text(79, 29.5, "Arial", 0, 12, suffix));
		label.addLine(new Line(78, 26, 14, 0.3, -90));
		label.addText(new Text(29, 37, "Arial", 0, 12, cpt_no));
		label.addText(new Text(65, 37, "Arial", 0, 12, "Glass"));
		label.addText(new Text(81, 35, "Arial", 0, 12, glass1));
		label.addText(new Text(81, 39, "Arial", 0, 12, glass2));
		label.addLine(new Line(64, 46.5, 15, 0.3, -90));
		label.addLine(new Line(78, 46.5, 15, 0.3, -90));
		label.addText(new Text(38, 50, "Arial", 0, 12, cnt));
		label.addText(new Text(65, 50, "Arial", 0, 12, "Date"));
		label.addText(new Text(79, 50, "Arial", 0, 12, date));
		label.addText(new Text(35, 57.5, "Arial", 0, 12, okcnt));
		label.addText(new Text(65, 57.5, "Arial", 0, 12, "Inspector"));
		label.addText(new Text(79, 57.5, "Arial", 0, 12, inspector));
		label.addText(new Text(40, 65, "Arial", 0, 12, remark));
		label.addText(new Text(40, 71, "Arial", 0, 12, substrate));
		label.addText(new Text(40, 77, "Arial", 0, 12, tcn_no));
		label.addText(new Text(35, 44, "Arial", 0, 12, item_no));
		label.addText(new Text(18, 84, "宋体", 0, 13, "評價類型代碼"));
		label.addText(new Text(40, 84, "Arial", 0, 13, pjlx));
		label.addText(new Text(55, 84, "Arial", 0, 13, "MADE IN CHINA"));
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();

	}

	public void PrintYZBDPallet(final String cus_id, final String box_id, final String cpt_type, final String suffix,
			final String cpt_no, final String po, String pCnt, final String item_no, final String cnt,
			final String date, final String okcnt, final String inspector, final String remark, final String substrate,
			final String tcn_no, final String pjlx) {

		LabelJX label = new LabelJX(100, 100, 300);
		label.addText(new Text(10, 5, "Arial", 0, 17, "CHUNGHWA PICTURE TUBES,LTD."));
		label.addRectangle(new Rectangle(3, 7, 95, 73, 0.3));
		label.addText(new Text(4, 10.5, "Arial", 0, 12, "Customer"));
		label.addLine(new Line(3, 12.5, 95, 0.3, 0));
		label.addText(new Text(4, 20, "Arial", 0, 12, "Pallet NO."));
		label.addLine(new Line(3, 26, 95, 0.3, 0));
		Code code = new Code(30, 13, 12, 0.30, box_id);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addLine(new Line(28, 7, 73, 0.3, -90));
		label.addText(new Text(4, 30, "Arial", 0, 12, "CPT Type"));
		label.addLine(new Line(3, 32.5, 95, 0.3, 0));
		label.addText(new Text(4, 37, "Arial", 0, 12, "CPT NO."));
		label.addLine(new Line(3, 39, 95, 0.3, 0));
		label.addText(new Text(4, 43, "Arial", 0, 11, "Customer Item NO."));
		label.addLine(new Line(3, 45.5, 95, 0.3, 0));
		label.addText(new Text(4, 50, "Arial", 0, 12, "Quantity"));
		label.addLine(new Line(3, 53, 95, 0.3, 0));
		label.addText(new Text(4, 57, "Arial", 0, 12, "OK/Total"));
		label.addText(new Text(4, 60, "Arial", 0, 12, "Count(pcs)"));
		label.addLine(new Line(3, 61.5, 95, 0.3, 0));
		label.addText(new Text(4, 65, "Arial", 0, 12, "Remark"));
		label.addLine(new Line(3, 67, 95, 0.3, 0));
		label.addText(new Text(4, 71, "Arial", 0, 12, "Substrate Type"));
		label.addLine(new Line(3, 73.5, 95, 0.3, 0));
		label.addText(new Text(4, 77.5, "Arial", 0, 12, "TCN NO."));
		label.addText(new Text(40, 10.5, "Arial", 0, 12, cus_id));
		label.addText(new Text(29, 30, "Arial", 0, 12, cpt_type));
		label.addText(new Text(65, 30, "Arial", 0, 12, "Suffix"));
		label.addLine(new Line(64, 26, 35.5, 0.3, -90));
		label.addLine(new Line(78, 26, 35.5, 0.3, -90));
		label.addText(new Text(79, 30, "Arial", 0, 12, suffix));
		label.addText(new Text(29, 37, "Arial", 0, 12, cpt_no));
		label.addText(new Text(65, 37, "Arial", 0, 12, "P/O NO."));
		label.addText(new Text(81, 37, "Arial", 0, 12, po));
		label.addText(new Text(65, 43, "Arial", 0, 11, "Date"));
		label.addText(new Text(79, 43, "Arial", 0, 12, date));
		label.addText(new Text(38, 50, "Arial", 0, 12, cnt));
		label.addText(new Text(65, 49, "Arial", 0, 12, "Package"));
		label.addText(new Text(65, 52.5, "Arial", 0, 11, "Count"));
		label.addText(new Text(81, 50, "Arial", 0, 12, pCnt));
		label.addText(new Text(35, 58, "Arial", 0, 12, okcnt));
		label.addText(new Text(65, 58, "Arial", 0, 12, "Inspector"));
		label.addText(new Text(79, 58, "Arial", 0, 12, inspector));
		label.addText(new Text(40, 65, "Arial", 0, 12, remark));
		label.addText(new Text(40, 71, "Arial", 0, 12, substrate));
		label.addText(new Text(40, 77.5, "Arial", 0, 12, tcn_no));
		label.addText(new Text(35, 43, "Arial", 0, 12, item_no));
		label.addText(new Text(18, 84, "宋体", 0, 13, "評價類型代碼"));
		label.addText(new Text(40, 84, "Arial", 0, 13, pjlx));
		label.addText(new Text(55, 84, "Arial", 0, 13, "MADE IN CHINA"));
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();

	}

	// hfxs
	public void PrintHFXS(final String boxID, final String customer_name, final String modelName, final String pnlCnt,
			final String shtCnt, final String totalCnt, final String date, final String productSpec, final String lotNo,
			final String jsonAry, final String productCate) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(2.8, 5.5, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "ROHS"));
		label.addText(new Text(2.8, 9.4, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(2.8, 13.2, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(56.2, 13.2, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(2.8, 17, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(56.2, 17, "Arial", 0, 13, "Q'TY(S) :" + totalCnt));
		label.addText(new Text(2.8, 20.8, "Arial", 0, 13, "Size:  " + productSpec));
		label.addText(new Text(56.2, 20.8, "Arial", 0, 13, "Lot No  :" + lotNo));
		label.addText(new Text(2.8, 24.6, "Arial", 0, 13, "Order No:  " + pnlCnt));
		label.addText(new Text(56.2, 24.6, "宋体", 0, 13, "Product Cate:" + productCate));
		Text text = new Text(2.8, 28.4, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(2.8, 29, 8, 0.25, boxID);

		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 5.8;
			double x2 = 36.8;
			double x3 = 67.8;
			double y = 40;
			double step = 3;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void printPrdID(final String printer, final String str) {
		try {
			System.out.println(str);
			PrintPrdInfo printData = new PrintPrdInfo();
			printData = JackUtil.fromJson(str, printData);
			String box_id = printData.getBox_id();
			double stdQty = printData.getStdQty();
			List<String> prdId = printData.getPrdAry();
			String dateString = JackUtil.getCurTime();
			int loopCnt = (int) Math.ceil(stdQty / 20);
			PrintMT excel = new PrintMT(dateString, "1", loopCnt);
			// 根据excel模板，新建workbook
			HSSFWorkbook workbook = excel.creatWorkbook();

			int i;
			int j;
			int index = 1;
			for (i = 0; i < loopCnt; i++) {
				HSSFSheet sheet = workbook.getSheet("sheet" + (String.valueOf(i + 1)));
				HSSFRow row = sheet.getRow(i + 5);
				HSSFCell cell = row.getCell(28);
				/* HSSFCell cell = sheet.getRow(1).getCell(28); */
				cell.setCellValue(box_id);
				for (j = 0; j < 20; j++, index++) {
					if (index <= stdQty) {
						if (!Util.isEmptyString(prdId.get(index - 1))) {
							cell = sheet.getRow(j + 8).getCell(1);
							cell.setCellValue(prdId.get(index - 1));
						}
					}
				}
			}
			String filename = excel.creatFile();
			FileOutputStream fileOut = new FileOutputStream(filename);
			workbook.write(fileOut);
			fileOut.flush();
			fileOut.close();
			excel.printExcel(printer, filename);
		} catch (Exception ex) {
			ex.printStackTrace();
			System.out.println(ex.toString());
		}
	}

	public void PrintPltHFXS(final String pallet_id, final String customer_name, final String model_name,
			final String date, final String pnl_qty, final String totalCnt, final String jsonAry) {

		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 98, 0.2));
		label.addText(new Text(8.8, 6.1, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "ROHS"));
		label.addText(new Text(8.8, 11.1, "宋体", 0, 13, "Client Name: " + customer_name));
		label.addText(new Text(8.8, 16.1, "Arial", 0, 13, "Model:  " + model_name));
		label.addText(new Text(8.8, 21.1, "Arial", 0, 13, "QTY:  " + pnl_qty));
		label.addText(new Text(8.8, 26.1, "Arial", 0, 13, "Total QTY:  " + totalCnt));
		label.addText(new Text(8.8, 31.1, "Arial", 0, 13, "PACK DATE:  " + date));
		label.addText(new Text(8.8, 36.1, "Arial", 0, 13, "PALLET:  " + pallet_id));
		Code code = new Code(8.8, 41.1, 9, 0.25, pallet_id);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 5.8;
			double x2 = 36.8;
			double x3 = 67.8;
			double y = 55;
			double step = 3;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintmtPallet(final String printer, final String cus, final String size, final String mdl,
			final String qty, final String date, final String note, final String pallet) {
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {

				System.out.println("Start2");

				ActiveXComponent axc = new ActiveXComponent("pt1.ct39");

				Dispatch dispatch = axc.getObject();
				Variant v = Dispatch.call(dispatch, "ct39", printer, cus, size, mdl, qty, date, note, pallet);

				return null;
			}
		});
	}

	// qrcode picture
	public void PrintQRPic(final String printer, final String str) {

		Qrcode rcode = new Qrcode();
		rcode.setQrcodeVersion(3);
		byte[] content = null;
		try {
			content = str.getBytes("utf-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		BufferedImage bufImg = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);

		Graphics2D gs = bufImg.createGraphics();
		gs.setBackground(Color.WHITE);
		gs.clearRect(0, 0, 300, 300);
		gs.setColor(Color.BLACK);
		if (content.length > 0 && content.length < 120) {
			boolean[][] codeOut = rcode.calQrcode(content);
			for (int i = 0; i < codeOut.length; i++) {
				for (int j = 0; j < codeOut.length; j++) {
					if (codeOut[j][i]) {
						gs.fillRect(j * 10 + 5, i * 10 + 5, 10, 10);
					}
				}
			}
			System.out.println("OK");
		} else {
			System.err.println("QRCode content bytes length = " + content.length + " not in [ 0,120 ]. ");
		}
		gs.dispose();
		bufImg.flush();
		File imgFile = new File("C:\\MESRP\\qr.jpg");
		try {
			ImageIO.write(bufImg, "jpg", imgFile);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// qrcode j-bj
	public void PrintQRMT1(final String printer) {
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {

				System.out.println("Start2");
				ActiveXComponent axc = new ActiveXComponent("pt1.ct42");

				Dispatch dispatch = axc.getObject();
				Variant v = Dispatch.call(dispatch, "ct42", printer);

				return null;
			}
		});
	}

	// qrcode j-bj
	public void PrintQRMT2(final String printer) {
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {

				System.out.println("Start2");
				ActiveXComponent axc = new ActiveXComponent("pt1.ct43");

				Dispatch dispatch = axc.getObject();
				Variant v = Dispatch.call(dispatch, "ct43", printer);

				return null;
			}
		});
	}

	// cx qr
	public void PrintJDFQR(final String str) {
		Label label = new Label(100, 100, 300);
		System.out.println("Start");
		try {
			label.addQRCode(str, 100, 100, 7);
			label.addQRCode(str, 500, 100, 7);
			label.addQRCode(str, 100, 500, 7);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.out.println("Start2");
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	// mt xm
	public void PrintXM(final String printer, final String box_id, final String customer_name, final String modelName,
			final String soID, final String shtCnt, final String totalCnt, final String strDate,
			final String productSpec, final String lotNo, final String jsonAry, final String prdCate) {
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {

				System.out.println("Start2");
				ObjectMapper mapper = new ObjectMapper();
				String[] ja = null;
				try {
					ja = mapper.readValue(jsonAry, String[].class);
				} catch (Exception e) {
					System.out.println("Error took place");
					e.printStackTrace();
				}
				String sht = "";
				for (int i = 0; i < 40; i++) {
					sht = sht + ja[i] + ",";
				}
				ActiveXComponent axc = new ActiveXComponent("pt1.ct45");

				Dispatch dispatch = axc.getObject();
				Variant v = Dispatch.call(dispatch, "ct45", printer, box_id, customer_name, modelName, soID, shtCnt,
						totalCnt, strDate, productSpec, lotNo, sht, prdCate);

				return null;
			}
		});
	}

	// mt xp
	public void PrintXPforMT(final String printer, final String customer_name, final String modelName,
			final String strDate, final String productSpec, final String woid, final String shtCnt,
			final String totalCnt, final String lotNo, final String prdCate, final String box_id,
			final String jsonAry) {
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {

				System.out.println("Start2");
				ObjectMapper mapper = new ObjectMapper();
				String[] ja = null;
				try {
					ja = mapper.readValue(jsonAry, String[].class);
				} catch (Exception e) {
					System.out.println("Error took place");
					e.printStackTrace();
				}
				String sht = "";
				for (int i = 0; i < 25; i++) {
					sht = sht + ja[i] + ",";
				}
				ActiveXComponent axc = new ActiveXComponent("pt1.ct46");

				Dispatch dispatch = axc.getObject();
				Variant v = Dispatch.call(dispatch, "ct46", printer, customer_name, modelName, strDate, productSpec,
						woid, shtCnt, totalCnt, lotNo, prdCate, box_id, sht);

				return null;
			}
		});
	}

	// new xp for cx
	public void printXPforCX(final String printer, final String type1, final String type2, final String cellcnt,
			final String shtcnt, final String date, final String boxid, final String jsonAry) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		String[] noAry = new String[40];
		for (int n = 0; n < 40; n++) {
			noAry[n] = "" + (n + 1);
		}
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		// box
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 97, 38, 0.3));
		label.addLine(new Line(1, 17, 97, 0.3, 0));
		label.addLine(new Line(1, 30, 97, 0.3, 0));
		label.addLine(new Line(1, 9, 60, 0.3, 0));
		label.addLine(new Line(15.5, 1, 38, 0.3, -90));
		label.addLine(new Line(25, 17, 13, 0.3, -90));
		label.addLine(new Line(49, 17, 13, 0.3, -90));
		label.addLine(new Line(61, 1, 29, 0.3, -90));
		label.addLine(new Line(85, 17, 13, 0.3, -90));

		label.addText(new Text(2, 5, "宋体", 0, 11, "Sharp P/N"));
		label.addText(new Text(2, 12, "宋体", 0, 11, "Sharp internal"));
		label.addText(new Text(2, 15, "宋体", 0, 11, "P/N"));
		label.addText(new Text(20, 6, "Arial Black", 0, 15, type1));
		label.addText(new Text(20, 14, "Arial Black", 0, 15, type2));
		label.addText(new Text(17, 24, "Arial", 0, 12, cellcnt));
		label.addText(new Text(53, 24, "Arial", 0, 12, shtcnt));
		label.addText(new Text(88, 24, "Arial", 0, 12, date));
		label.addText(new Text(26, 36, "Arial Black", 0, 15, boxid));
		label.addText(new Text(2, 21, "Arial", 0, 12, "Quantity"));
		label.addText(new Text(3, 25, "Arial", 0, 12, "of cells"));
		label.addText(new Text(3, 29, "宋体", 0, 12, "セル数"));
		label.addText(new Text(29, 21, "Arial", 0, 12, "Quantity of"));
		label.addText(new Text(31, 25, "Arial", 0, 12, "Kibans"));
		label.addText(new Text(31, 29, "宋体", 0, 12, "基板数"));
		label.addText(new Text(67, 24, "宋体", 0, 12, "出荷日付"));
		label.addText(new Text(4, 36, "Arial", 0, 16, "LOT"));
		// glass
		label.addRectangle(new Rectangle(1, 43, 97, 50, 0.3));
		label.addLine(new Line(1, 48, 97, 0.3, 0));
		label.addLine(new Line(1, 53, 97, 0.3, 0));
		label.addLine(new Line(1, 58, 97, 0.3, 0));
		label.addLine(new Line(1, 63, 97, 0.3, 0));
		label.addLine(new Line(1, 68, 97, 0.3, 0));
		label.addLine(new Line(1, 73, 97, 0.3, 0));
		label.addLine(new Line(1, 78, 97, 0.3, 0));
		label.addLine(new Line(1, 83, 97, 0.3, 0));
		label.addLine(new Line(1, 88, 97, 0.3, 0));
		label.addLine(new Line(25, 43, 50, 0.3, -90));
		label.addLine(new Line(49, 43, 50, 0.3, -90));
		label.addLine(new Line(73, 43, 50, 0.3, -90));
		double q1 = 1.5;
		double q2 = 25.5;
		double q3 = 49.5;
		double q4 = 73.6;
		double y = 46;
		double step = 5;
		for (int j = 0; j < noAry.length; j++) {
			double q = 0;
			if (j < 10) {
				q = q1;
			} else if (j >= 10 && j < 20) {
				q = q2;
			} else if (j >= 20 && j < 30) {
				q = q3;
			} else if (j >= 30 && j < 40) {
				q = q4;
			}
			double _y1 = y + (j % 10) * step;
			label.addText(new Text(q, _y1, "Arial", 0, 8.5, ja[j]));
		}
		try {
			label.print(printer);
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void printXPpalletforCX(final String printer, final String jzID, final String date, final String pn,
			final String lotNo, final String shtcnt, final String cellcnt, final String upn, final String upnDown,
			final String pallet1, final String pallet2, final String pallet3, final String pallet4,
			final String pallet5, final String pallet6, final String dir) {

		Label label = new Label(130, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 127, 54.7, 0.3));
		label.addLine(new Line(1, 8, 127, 0.2, 0));
		label.addLine(new Line(1, 9, 127, 0.2, 0));
		label.addLine(new Line(1, 14.2, 127, 0.2, 0));
		label.addLine(new Line(1, 15.2, 127, 0.2, 0));
		label.addLine(new Line(1, 20.4, 127, 0.2, 0));
		label.addLine(new Line(1, 21.4, 127, 0.2, 0));
		label.addLine(new Line(1, 26.6, 127, 0.2, 0));
		label.addLine(new Line(1, 27.6, 127, 0.2, 0));
		label.addLine(new Line(1, 32.8, 127, 0.2, 0));
		label.addLine(new Line(1, 38, 127, 0.2, 0));
		label.addLine(new Line(1, 38.7, 127, 0.2, 0));
		label.addLine(new Line(1, 43.9, 127, 0.2, 0));
		label.addLine(new Line(1, 44.6, 127, 0.2, 0));
		label.addLine(new Line(1, 49.8, 127, 0.2, 0));
		label.addLine(new Line(1, 50.5, 127, 0.2, 0));

		label.addLine(new Line(43, 8, 6.2, 0.2, -90));
		label.addLine(new Line(43, 15.2, 5.2, 0.2, -90));
		label.addLine(new Line(43, 21.4, 5.2, 0.2, -90));
		label.addLine(new Line(43, 27.6, 10.4, 0.2, -90));
		label.addLine(new Line(43, 38.7, 5.2, 0.2, -90));
		label.addLine(new Line(43, 44.6, 5.2, 0.2, -90));
		label.addLine(new Line(43, 50.5, 5.2, 0.2, -90));
		label.addLine(new Line(86, 8, 6.2, 0.2, -90));
		label.addLine(new Line(86, 15.2, 5.2, 0.2, -90));
		label.addLine(new Line(86, 21.4, 5.2, 0.2, -90));
		label.addLine(new Line(86, 27.6, 10.4, 0.2, -90));
		label.addLine(new Line(86, 38.7, 5.2, 0.2, -90));
		label.addLine(new Line(86, 44.6, 5.2, 0.2, -90));
		label.addLine(new Line(86, 50.5, 5.4, 0.2, -90));

		label.addRectangle(new Rectangle(1, 62.7, 127, 30, 0.3));
		label.addLine(new Line(1, 67.7, 127, 0.2, 0));
		label.addLine(new Line(1, 72.7, 127, 0.2, 0));
		label.addLine(new Line(1, 77.7, 127, 0.2, 0));
		label.addLine(new Line(1, 82.7, 127, 0.2, 0));
		label.addLine(new Line(1, 87.7, 127, 0.2, 0));

		label.addText(new Text(2, 6, "Arial Black", 0, 16, "Panel shipment label"));
		label.addText(new Text(92, 6, "Arial Black", 0, 16, jzID));
		label.addText(new Text(110, 6, "Arial Black", 0, 16, date));
		label.addText(new Text(2, 13, "Arial", 0, 14, "Sharp internal P/N"));
		label.addText(new Text(44, 13, "楷体", 0, 14, pn));
		label.addText(new Text(2, 19.2, "Arial", 0, 14, "Lot No"));
		label.addText(new Text(44, 19.2, "楷体", 0, 14, lotNo));
		label.addText(new Text(2, 25.4, "Arial", 0, 14, "Quantity"));
		label.addText(new Text(44, 25.4, "楷体", 0, 14, shtcnt));
		label.addText(new Text(90, 25.4, "Arial", 0, 14, "Cells:"));
		label.addText(new Text(110, 25.4, "楷体", 0, 14, cellcnt));
		label.addText(new Text(2, 31.6, "Arial", 0, 14, "Sharp P/N"));
		label.addText(new Text(44, 31.6, "楷体", 0, 14, upn));
		label.addText(new Text(44, 36.8, "楷体", 0, 14, upnDown));
		label.addText(new Text(2, 42.7, "Arial", 0, 14, "Panel shipment ID"));
		label.addText(new Text(44, 42.7, "楷体", 0, 14, pallet1));
		label.addText(new Text(87, 42.7, "楷体", 0, 14, pallet2));
		label.addText(new Text(44, 48.6, "楷体", 0, 14, pallet3));
		label.addText(new Text(87, 48.6, "楷体", 0, 14, pallet4));
		label.addText(new Text(44, 54.5, "楷体", 0, 14, pallet5));
		label.addText(new Text(87, 54.5, "楷体", 0, 14, pallet6));
		label.addText(new Text(63, 66.5, "Arial", 0, 14, "GIS"));
		label.addText(new Text(56, 71.5, "Arial", 0, 14, dir));
		label.addText(new Text(62, 76.5, "Arial", 0, 14, "L C D"));
		label.addText(new Text(57, 81.5, "楷体", 0, 14, "C/No.D" + lotNo.substring(lotNo.length() - 3, lotNo.length())));
		label.addText(new Text(62, 86.5, "Arial", 0, 14, "P/No."));
		label.addText(new Text(53, 91.5, "Arial", 0, 14, "MADE IN CHINA"));

		try {
			label.print(printer);
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void printXPshtforCX(final String printer, final String no, final String jsonAry) {

		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		String[] noAry = new String[40];
		for (int n = 0; n < 40; n++) {
			noAry[n] = "" + (n + 1);
		}
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}

		Label label = new Label(170, 100, 300);
		/*
		 * label.addRectangzle(new Rectangle(1, 1, 165, 44, 0.2));
		 * label.addLine(new Line(1,23,165,0.2,0)); label.addLine(new
		 * Line(1,35,165,0.2,0)); label.addLine(new Line(38,12,83,0.2,0));s
		 * label.addLine(new Line(38,1,44,0.2,-90)); label.addLine(new
		 * Line(61,23,12,0.2,-90)); label.addLine(new Line(106,23,12,0.2,-90));
		 * label.addLine(new Line(121,1,34,0.2,-90)); label.addLine(new
		 * Line(146,23,12,0.2,-90));
		 */

		label.addText(new Text(1, 15, "Arial Black", 0, 12, "BOX NO."));
		label.addText(new Text(3.8, 15, "Arial", 0, 12, "基板No."));
		label.addText(new Text(7.8, 15, "宋体", 0, 12, "基板詳細"));
		label.addText(new Text(35.8, 15, "Arial", 0, 12, "基板No."));
		label.addText(new Text(39.8, 15, "宋体", 0, 12, "基板詳細"));
		label.addText(new Text(67.8, 15, "Arial", 0, 12, "基板No."));
		label.addText(new Text(71.8, 15, "宋体", 0, 12, "基板詳細"));
		label.addText(new Text(99.8, 15, "Arial", 0, 12, "基板No."));
		label.addText(new Text(103.8, 15, "宋体", 0, 12, "基板詳細"));

		double x1 = 3.8;
		double x2 = 35.8;
		double x3 = 67.8;
		double x4 = 99.8;
		double y = 20;
		double step = 3.5;
		for (int i = 0; i < noAry.length; i++) {
			double x = 0;
			if (i < 10) {
				x = x1;
			} else if (i >= 10 && i < 20) {
				x = x2;
			} else if (i >= 20 && i < 30) {
				x = x3;
			} else if (i >= 30 && i < 40) {
				x = x4;
			}
			double _y = y + (i % 10) * step;
			label.addText(new Text(x, _y, "Arial", 0, 12, noAry[i]));
		}
		double q1 = 5.8;
		double q2 = 37.8;
		double q3 = 69.8;
		double q4 = 101.8;
		for (int j = 0; j < noAry.length; j++) {
			double q = 0;
			if (j < 10) {
				q = q1;
			} else if (j >= 10 && j < 20) {
				q = q2;
			} else if (j >= 20 && j < 30) {
				q = q3;
			} else if (j >= 30 && j < 40) {
				q = q4;
			}
			double _y1 = y + (j % 10) * step;
			label.addText(new Text(q, _y1, "Arial", 0, 12, ja[j]));
		}
		try {
			label.print(printer);
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void PrintTWQCN(final String soid, final String cus_cus_id, final String model_name, final String box_id,
			final String shtCnt, final String cellCnt) {

		Label label = new Label(100, 100, 300);
		label.addText(new Text(2, 21, "Arial", 0, 18, "PO.NO."));
		label.addText(new Text(2, 35, "Arial", 0, 18, "Part ID."));
		label.addText(new Text(2, 45, "Arial", 0, 18, "Model Name"));
		label.addText(new Text(2, 62, "Arial", 0, 18, "Carton ID."));
		label.addText(new Text(2, 75, "Arial", 0, 18, "Quantities"));
		label.addText(new Text(45, 75, "Arial", 0, 18, "ALL"));
		Code code1 = new Code(21, 15, 15, 0.25, soid);
		try {
			label.addCodes(code1);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(20, 35, "Arial", 0, 18, cus_cus_id));
		Code code2 = new Code(31, 38, 15, 0.25, model_name);
		try {
			label.addCodes(code2);
		} catch (IOException e) {
			e.printStackTrace();
		}
		Code code3 = new Code(26, 55, 15, 0.25, box_id);
		try {
			label.addCodes(code3);
		} catch (IOException e) {
			e.printStackTrace();
		}
		label.addText(new Text(25, 75, "Arial", 0, 18, shtCnt));
		label.addText(new Text(55, 75, "Arial", 0, 18, cellCnt));
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}

	public void printDeliveryNoteForMT1(final String printer, final String str) {
		try {
			System.out.println(str);
			DeliveryNotePrint printInfo = new DeliveryNotePrint();
			printInfo = JackUtil.fromJson(str, printInfo);
			String dateString = JackUtil.getCurDate();
			int loop = 1;
			PrintMT excel = new PrintMT(dateString, "2", 1);
			// 根据excel模板，新建workbook
			HSSFWorkbook workbook = excel.creatWorkbook();

			int i;
			int j;
			int m;
			for (i = 0; i < loop; i++) {
				HSSFSheet sheet = workbook.getSheet("sheet" + (String.valueOf(i + 1)));
				HSSFRow sourceRow = sheet.getRow(7);
				int cellCnt = sourceRow.getLastCellNum();
				int newRowCnt = printInfo.getIary().size();
				if (newRowCnt > 1) {
					sheet.shiftRows(8, sheet.getLastRowNum(), newRowCnt - 1, true, false);
					for (j = 1; j < newRowCnt; j++) {
						HSSFRow targetRow = null;
						HSSFCell sourceCell = null;
						HSSFCell targetCell = null;
						targetRow = sheet.createRow(7 + j);
						targetRow.setHeight(sourceRow.getHeight());

						for (m = sourceRow.getFirstCellNum(); m < cellCnt; m++) {
							sourceCell = sourceRow.getCell(m);
							targetCell = targetRow.createCell(m);
							targetCell.setCellStyle(sourceCell.getCellStyle());
							targetCell.setCellType(sourceCell.getCellType());
						}
					}
				}

				String dateStr = JackUtil.getCurTime2();
				String year = dateStr.split("-")[0];
				String month = dateStr.split("-")[1];
				String day = dateStr.split("-")[2];

				sheet.getRow(2).getCell(11).setCellValue(printInfo.getLk() + printInfo.getOemdn());
				sheet.getRow(3).getCell(11).setCellValue("共" + printInfo.getPallet_cnt() + "托--" + printInfo.getDir());

				int pnl_cnt = 0;
				int box_cnt = 0;
				for (j = 0; j < newRowCnt; j++) {
					BoxInfo boxInfo = printInfo.getIary().get(j);
					sheet.getRow(7 + j).getCell(0).setCellValue(j + 1);
					sheet.getRow(7 + j).getCell(1).setCellValue("/");
					sheet.getRow(7 + j).getCell(2).setCellValue(boxInfo.getMtrl_desc());
					sheet.getRow(7 + j).getCell(3).setCellValue(boxInfo.getPrd_qty());
					sheet.getRow(7 + j).getCell(4).setCellValue(boxInfo.getPrd_qty());
					sheet.getRow(7 + j).getCell(5).setCellValue(boxInfo.getGrain_cnt());
					sheet.getRow(7 + j).getCell(6).setCellValue("——");
					sheet.getRow(7 + j).getCell(7).setCellValue(boxInfo.getBox_cnt());
					sheet.getRow(7 + j).getCell(8).setCellValue("SH");
					sheet.getRow(7 + j).getCell(9).setCellValue(boxInfo.getMtrl_remark());
					sheet.getRow(7 + j).getCell(10).setCellValue("——");
					sheet.getRow(7 + j).getCell(11).setCellValue("——");
					sheet.getRow(7 + j).getCell(12).setCellValue(printInfo.getOemdn().substring(0, 10));
					sheet.getRow(7 + j).getCell(13).setCellValue("——");
					pnl_cnt = pnl_cnt + Integer.parseInt(boxInfo.getPrd_qty());
					box_cnt = box_cnt + Integer.parseInt(boxInfo.getBox_cnt());
				}
				sheet.getRow(7 + newRowCnt).getCell(4).setCellValue(pnl_cnt + "");
				sheet.getRow(7 + newRowCnt).getCell(7).setCellValue(box_cnt + "");
				sheet.getRow(14 + newRowCnt).getCell(0).setCellValue("送货日期：" + year + "." + month + "." + day);
			}

			String filename = excel.creatFile();
			FileOutputStream fileOut = new FileOutputStream(filename);
			workbook.write(fileOut);
			fileOut.flush();
			fileOut.close();
			excel.printExcel(printer, filename);
		} catch (Exception ex) {
			ex.printStackTrace();
			System.out.println(ex.toString());
		}
	}

	public void printDeliveryNoteForMT2(final String printer, final String str) {
		try {
			DeliveryNotePrint printInfo = new DeliveryNotePrint();
			printInfo = JackUtil.fromJson(str, printInfo);
			String dateString = JackUtil.getCurDate();
			int loop = 1;
			PrintMT excel = new PrintMT(dateString, "3", 1);
			// 根据excel模板，新建workbook
			HSSFWorkbook workbook = excel.creatWorkbook();

			int i;
			int j;
			int m;
			for (i = 0; i < loop; i++) {

				HSSFSheet sheet = workbook.getSheet("sheet" + (String.valueOf(i + 1)));
				HSSFRow sourceRow = sheet.getRow(6);
				int cellCnt = sourceRow.getLastCellNum();
				int newRowCnt = printInfo.getIary().size();
				if (newRowCnt > 1) {
					sheet.shiftRows(7, sheet.getLastRowNum(), newRowCnt - 1, true, false);
					for (j = 1; j < newRowCnt; j++) {
						HSSFRow targetRow = null;
						HSSFCell sourceCell = null;
						HSSFCell targetCell = null;
						targetRow = sheet.createRow(6 + j);
						targetRow.setHeight(sourceRow.getHeight());

						for (m = sourceRow.getFirstCellNum(); m < cellCnt; m++) {
							sourceCell = sourceRow.getCell(m);
							targetCell = targetRow.createCell(m);
							targetCell.setCellStyle(sourceCell.getCellStyle());
							targetCell.setCellType(sourceCell.getCellType());
						}
					}
				}
				String crt_value1 = sheet.getRow(2).getCell(0).getStringCellValue();
				String crt_value2 = sheet.getRow(2).getCell(7).getStringCellValue();
				String crt_value3 = sheet.getRow(3).getCell(0).getStringCellValue();
				String crt_value4 = sheet.getRow(4).getCell(7).getStringCellValue();

				String dateStr = JackUtil.getCurTime2();
				String year = dateStr.split("-")[0];
				String month = dateStr.split("-")[1];
				String day = dateStr.split("-")[2];
				String hour = dateStr.split("-")[3];
				String minute = dateStr.split("-")[4];

				sheet.getRow(2).getCell(0).setCellValue(crt_value1 + printInfo.getCustomer_id());
				sheet.getRow(2).getCell(7)
						.setCellValue(crt_value2 + printInfo.getKh() + year.substring(2) + month + day);
				sheet.getRow(3).getCell(0).setCellValue(crt_value3 + printInfo.getCustomer_add());
				sheet.getRow(4).getCell(7).setCellValue(crt_value4 + year + "." + month + "." + day);
				int pnl_cnt = 0;
				for (j = 0; j < newRowCnt; j++) {
					BoxInfo boxInfo = printInfo.getIary().get(j);
					sheet.getRow(6 + j).getCell(0).setCellValue(j + 1);
					sheet.getRow(6 + j).getCell(1).setCellValue(boxInfo.getProc_name());
					sheet.getRow(6 + j).getCell(2).setCellValue(boxInfo.getMdl_typ());
					sheet.getRow(6 + j).getCell(3).setCellValue(boxInfo.getMdl_id());
					sheet.getRow(6 + j).getCell(4).setCellValue(boxInfo.getMdl_dsc());
					sheet.getRow(6 + j).getCell(5).setCellValue(boxInfo.getPrd_qty());
					sheet.getRow(6 + j).getCell(6).setCellValue(boxInfo.getGrain_cnt());
					sheet.getRow(6 + j).getCell(7).setCellValue(boxInfo.getRemark1());
					sheet.getRow(6 + j).getCell(8).setCellValue(boxInfo.getRemark2());
					pnl_cnt = pnl_cnt + Integer.parseInt(boxInfo.getPrd_qty());
				}
				sheet.getRow(6 + newRowCnt).getCell(5).setCellValue(pnl_cnt + "");
				sheet.getRow(6 + newRowCnt).getCell(6).setCellValue("箱数：" + newRowCnt + "送货时间：" + hour + ":" + minute);
			}

			String filename = excel.creatFile();
			FileOutputStream fileOut = new FileOutputStream(filename);
			workbook.write(fileOut);
			fileOut.flush();
			fileOut.close();
			excel.printExcel(printer, filename);
		} catch (Exception ex) {
			ex.printStackTrace();
			System.out.println(ex.toString());
		}
	}

	// TPK
	public void PrintTPK(final String cusName, final String modelName, final String shtCnt, final String lotNo,
			final String poNo, final String prodCate, final String date, final String toDate, final String wd,
			final String sd, final String boxID, final String jsonAry) {
		ObjectMapper mapper = new ObjectMapper();
		String[] ja = null;
		try {
			ja = mapper.readValue(jsonAry, String[].class);
		} catch (Exception e) {
			System.out.println("Error took place");
			e.printStackTrace();
		}
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 97, 0.2));
		label.addText(new Text(8.8, 6.1, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 6.1, "Arial", 0, 13, "HF ROHS"));
		
		label.addText(new Text(8.8, 11.1, "宋体", 0, 13, "Client Name: " + cusName));
		label.addText(new Text(8.8, 15.6, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(8.8, 20.1, "Arial", 0, 13, "Q'TY(Q) :" + shtCnt));
		label.addText(new Text(8.8, 24.6, "Arial", 0, 13, "Lot No  :" + lotNo));
		label.addText(new Text(8.8, 29.1, "Arial", 0, 13, "PO No:  " + poNo));
		label.addText(new Text(8.8, 33.6, "宋体", 0, 13, "Product Cate:" + prodCate));
		
		
		label.addText(new Text(56.2, 15.6, "Arial", 0, 13, "Date:  " + date));
		label.addText(new Text(56.2, 20.1, "宋体", 0, 13, "有效期(保质期) :" + toDate));
		label.addText(new Text(56.2, 24.6, "宋体", 0, 13, "存储温度:  " + wd));
		label.addText(new Text(56.2, 29.1, "宋体", 0, 13, "存储湿度:  " + sd));
		
		
		
		
		Text text = new Text(8.8, 39, "Arial Black", 0, 15, boxID);
		label.addText(text);
		Code code = new Code(8.8, 41, 8, 0.25, boxID);

		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (ja == null) {
			System.out.println("Sheet array is empty");
		} else {
			double x1 = 8.8;
			double x2 = 37.8;
			double x3 = 68.8;
			double y = 53;
			double step = 3.5;
			for (int i = 0; i < ja.length; i++) {
				double x = 0;
				if (i % 3 == 0) {
					x = x1;
				} else if (i % 3 == 1) {
					x = x2;
				} else {
					x = x3;
				}
				double _y = y + (i / 3) * step;
				label.addText(new Text(x, _y, "Arial", 0, 12, ja[i]));
			}
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}
	
	public void PrintPltTPK(final String cusName, final String modelName, final String lotNo, final String poNo,
			final String pnlCnt, final String ttlCnt,final String date, final String toDate,final String wd,
			final String sd, final String palletId) {

		ObjectMapper mapper = new ObjectMapper();
		Label label = new Label(100, 100, 300);
		label.addRectangle(new Rectangle(1, 1, 98, 98, 0.2));
		label.addText(new Text(8.8, 6, "宋体", 0, 18, "长信科技"));
		label.addText(new Text(72.8, 6, "Arial", 0, 13, "HF ROHS"));
		label.addText(new Text(8.8, 13, "宋体", 0, 13, "Client Name: " + cusName));
		label.addText(new Text(8.8, 18, "Arial", 0, 13, "Model:  " + modelName));
		label.addText(new Text(8.8, 23, "Arial", 0, 13, "Lot No:  " + lotNo));
		label.addText(new Text(8.8, 28, "Arial", 0, 13, "PO No:  " + poNo));
		label.addText(new Text(8.8, 33, "Arial", 0, 13, "QTY(Q):  " + pnlCnt));
		label.addText(new Text(8.8, 38, "Arial", 0, 13, "QTY(TTL):  " + ttlCnt));
		label.addText(new Text(8.8, 43, "Arial", 0, 13, "PACK DATE:  " + date));
		label.addText(new Text(8.8, 48, "宋体", 0, 13, "有效期(保质期):  " + toDate));
		label.addText(new Text(8.8, 53, "宋体", 0, 13, "存储温度:  " + wd));
		label.addText(new Text(8.8, 58, "宋体", 0, 13, "存储湿度:  " + sd));
		label.addText(new Text(8.8, 63, "Arial", 0, 13, "PALLET:  " + palletId));
		Code code = new Code(8.8, 68, 9, 0.25, palletId);
		try {
			label.addCode(code);
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			label.print();
		} catch (Exception e) {
			e.printStackTrace();
		}
		label.dispose();
	}


}
